/**
 * Created by yuesir on 2017/6/29.
 */

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
//关注和取消关注
$('.like-button').click(function (e) {
    var $target = $(e.target);
    var $currStatus = $target.attr('like-value');
    var $userId = $target.attr('like-user');
    
    if (1 == $currStatus) {
        //取消关注
        var url = '/user/' + $userId + '/unfan';
        $.ajax({
            "url" : url,
            "type":'POST',
            "success":function (data) {
                if (data.error > 0) {
                    alert(data.msg);
                    return;
                }

                $target.attr('like-value', 0).text('关注');
            }
        })
    } else {
        //取消关注
        var url = '/user/' + $userId + '/fan';
        $.ajax({
            "url" : url,
            "type":'POST',
            "success":function (data) {
                if (data.error > 0) {
                    alert(data.msg);
                    return;
                }

                $target.attr('like-value', 1).text('取消关注');
            }
        })
    }
    
});